import 'package:star_author/config/api.dart';
import 'package:star_author/config/base_configuration.dart';
import 'package:star_author/utils/utils.dart';
import 'package:star_author/views/products/product_list_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../bidding_product_list_item.dart';

class RelateListWidget extends StatefulWidget {
  final Map<String, dynamic> queryParameters;
  final Color? color;
  final BiddingProductListItemStyle? style;
  final String? title;
  final BiddingProductListItemFormType? detail;

  RelateListWidget({
    Key? key,
    required this.queryParameters,
    this.color,
    this.style,
    this.detail,
    this.title,
  }) : super(key: key);

  _RelateListWidget createState() => _RelateListWidget();
}

class _RelateListWidget extends State<RelateListWidget> {
  List<dynamic> list = [];

  void initAsyncData() async {
    final res = await API.getRelate(widget.queryParameters);
    list = res.data['data'];
    if (mounted) setState(() {});
  }

  @override
  void initState() {
    super.initState();
    initAsyncData();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: widget.color ?? Color(0xFFF5F5F5),
      child: Column(
        children: [
          Container(
            padding: GetPadding.only(top: 20.w),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Image(
                  image: AssetImage(
                    'images/lt_common/title_line_left.png',
                  ),
                  width: 98.w,
                ),
                Container(
                  margin: GetPadding.only(left: 17.w, right: 17.w),
                  child: Text(
                    widget.title ?? "相关货品",
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                      fontSize: 16.sp,
                      color: ColorConf.normal,
                    ),
                  ),
                ),
                Image(
                  image: AssetImage(
                    'images/lt_common/title_line_right.png',
                  ),
                  width: 98.w,
                ),
              ],
            ),
          ),
          ProductListWidget.normal(
            itemCount: list.length,
            list: list,
            style: widget.style ?? BiddingProductListItemStyle.Inside,
            detail:
                widget.detail ?? BiddingProductListItemFormType.BiddingDetail,
            refreshPage: () {},
          ),
          Container(
            padding: GetPadding.only(top: 20.w, bottom: 15.w),
            child: Text(
              '更多好货去首页逛逛吧～',
              style: TextStyle(
                fontSize: 12.sp,
                color: ColorConf.lightGray,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
